
import { produce } from 'immer'

const initState = {
  count: 0,
  token: '',
  routes: []
}

const reducer = (state = initState, { type, value }) => {
  // type：接收传来的名字，value：接收传来的值
  console.log('type:',type, value)
  switch (type) {
    case 'add_token':
      return {
        ...state,
        token: value,
      }
    case 'add_count':
      return produce(state, draftState => {
        draftState.count = state.count + value
      })
    case 'logOut':
      return initState
    case 'setRoute':
      return produce(state, draftState => {
        draftState.routes = value
      })
    default:
      return state
  }
}

export { reducer }